package com.yichat.micro.msghttpservice;

import com.yichat.micro.msghttpservice.common.Constants;
import com.yichat.micro.msghttpservice.common.util.JsonUtil;
import lombok.Data;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * Created by chenmohan on 2019/04/19
 *
 * @description
 */
@RestController
public class BatchTestController {

    @RequestMapping("/b1")
    public String b1(Foo student) throws InterruptedException {
        Thread.sleep(3000);
        student.setTotal(student.getA() + student.getB());
        //System.err.println("延迟3秒,【b1】处理: " + student);
        return Constants.ok;
    }

    @RequestMapping("/b2")
    public String b2(Foo student) throws InterruptedException {
        Thread.sleep(3000);
        student.setTotal(student.getA() + student.getB());
        //System.err.println("延迟3秒,【b2】处理: " + student);
        return Constants.ok;
    }

    @RequestMapping("/b3")
    public String b3(@RequestBody String data) {
        TestController.Foo foo = JsonUtil.toBean(data, TestController.Foo.class);
        System.err.println(foo);
        return Constants.ok;
    }

    @Data
    public static class Foo {
        private String name;
        private Integer age;
        private Integer a;
        private Integer b;
        private Integer total;
    }
}
